package com.ardf.controller;

import com.ardf.common.CodeEnum;
import com.ardf.common.ReturnResult;
import com.ardf.entity.Competition;
import com.ardf.service.PrintService;
import com.fazecast.jSerialComm.SerialPort;
import jakarta.annotation.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.socket.WebSocketSession;

/**
 * author:容伟洪
 * time:2025-3-13
 * description：用于接收打印请求
 */
@RestController
@RequestMapping("/ardf/print")
public class PrintController {

    @Resource
    private PrintService printService;

    /**
     * author:容伟洪
     * time:2025-3-13
     * description：开始比赛的个人赛成绩打印请求处理
     */
    @GetMapping("/printPersonGrade")
    public ResponseEntity<ReturnResult> printPersonGrade(@RequestParam("cardId") Long cardId,
                                                         @RequestParam("projectId") Long projectId,
                                                         @RequestParam("competitionId")Long competitionId,
                                                         @RequestParam("project")String project){


        Boolean result=printService.printPerson(competitionId,project,cardId,projectId);
        if(result){
            return ResponseEntity.ok(new ReturnResult(CodeEnum.SUCCESS));
        }
        return ResponseEntity.status(HttpStatus.FORBIDDEN).body(new ReturnResult(CodeEnum.PRINTER_WAS_CLOSE));

    }

    /**
     * author:容伟洪
     * time:2025-3-13
     * description：开始比赛的接力赛成绩打印请求处理
     */
    @GetMapping("/printTeamGrade")
    public ResponseEntity<ReturnResult> printTeamGrade(@RequestParam("teamId") Long teamId,
                                                         @RequestParam("projectId") Long projectId,
                                                         @RequestParam("competitionId")Long competitionId,
                                                         @RequestParam("project")String project){

        Boolean result=printService.printTeam(competitionId,project,teamId,projectId);
        if(result){
            return ResponseEntity.ok(new ReturnResult(CodeEnum.SUCCESS));
        }
        return ResponseEntity.status(HttpStatus.FORBIDDEN).body(new ReturnResult(CodeEnum.PRINTER_WAS_CLOSE));

    }

}
